﻿using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Data;
using System.Collections.ObjectModel;
using System.Linq;
using System;
using System.Windows.Controls;
using System.ComponentModel;
using ASPItalia.ModelVirtualCasting.Web.RiaServices;

namespace ASPItalia.ModelVirtualCasting.Silverlight.BackOffice.Converters
{
    public class TypeListConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            PeopleType _retValue = null;

            string _value = (string)value;

            if (_value != null)
            {
                _retValue = (from p in PeopleTypeCollection.Elements
                          where p.Code.Equals(_value, StringComparison.InvariantCultureIgnoreCase)
                          select p).FirstOrDefault();
            }

            return _retValue;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            PeopleType pt = (PeopleType)value;
            return pt.Code;
        }
    }

    public class PeopleTypeCollection : ObservableCollection<PeopleType>
    {
        public static PeopleTypeCollection Elements { get; set; }

        static PeopleTypeCollection()
        {
            Elements = new PeopleTypeCollection() { new ModelType(), new CandidateType() };
        }
    }
}